﻿<UserControl 	
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 	
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 	
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 	
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:DiskUsage"  	
    mc:Ignorable="d" 	
    x:Class="DiskUsage.DirectoryTreeView" 	
    x:Name="UserControl" 	d:DesignWidth="100" d:DesignHeight="100">
    <Grid x:Name="LayoutRoot">
        <TreeView x:Name="m_treeView" BorderThickness="0" d:LayoutOverrides="Width, Height" >
            <TreeView.ContextMenu>
                <ContextMenu StaysOpen="true">
                    <MenuItem Header="Calculate Size" Click="CalculateSize_Click"/>
                    <MenuItem Header="Refresh" Click="Refresh_Click"/>
                </ContextMenu>
            </TreeView.ContextMenu>
            <TreeView.Resources>
                <Style TargetType="TreeViewItem">
                    <Style.Resources>
                        <Brush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</Brush>
                    </Style.Resources>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="#EFF8FD"/>
                            <Setter Property="BorderBrush" Value="#99DEFD"/>
                            <Setter Property="Foreground" Value="Black"/>
                        </Trigger>
                    </Style.Triggers>

                    <EventSetter Event="MouseRightButtonDown" Handler="TreeViewItem_MouseRightButtonDown"/>
                </Style>

            </TreeView.Resources>
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate DataType="{x:Type local:DirectoryPresentationBase}" ItemsSource="{Binding Children}">
                    <Border  Name="SelectedBorder"  CornerRadius="3"
                             Background="{Binding Background, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                             BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                                     BorderThickness="1" >
                        <StackPanel Orientation="Horizontal" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp">
                            <Image x:Name="img" Width="24" Height="16" Stretch="None" Source="{Binding SmallIcon}"/>
                            <TextBlock Text="{Binding Name}" Margin="5,0" />
                        </StackPanel>
                    </Border>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</UserControl>